package com.its.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.its.mapper.BusClaimReportMapper;
import com.its.mapper.HupCompanyMapper;
import com.its.pojo.BusDispatchInfo;
import com.its.pojo.WorkingPersonnel;
import com.its.mapper.WorkingPersonnelMapper;
import com.its.service.HupCompanyService;
import com.its.service.WorkingPersonnelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.its.web.param.WorkingPersonnelControllerParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 工作人员信息表 服务实现类
 * </p>
 *
 * @author 朱厚强
 * @since 2023年12月27日
 */
@Service
public class WorkingPersonnelServiceImpl extends ServiceImpl<WorkingPersonnelMapper, WorkingPersonnel> implements WorkingPersonnelService {
    @Autowired
    private WorkingPersonnelMapper workingPersonnelMapper;
    @Autowired
    private HupCompanyMapper hupCompanyMapper;
    @Override
    public List<WorkingPersonnel> selectCompanyById(String companyId) {
        LambdaQueryWrapper<WorkingPersonnel> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WorkingPersonnel::getCompanyId,companyId);//
        wrapper.eq(WorkingPersonnel::getPositionId,3);// fixme 3为调度员
        List<WorkingPersonnel> list = workingPersonnelMapper.selectList(wrapper);
        return list;
    }

    @Override
    public PageInfo<WorkingPersonnel> selectList(WorkingPersonnelControllerParam param) {
        // 开始分页
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        // 用lambda 表达式的方式生成
        LambdaQueryWrapper<WorkingPersonnel> queryWrapper = new LambdaQueryWrapper<>();
        // 员工姓名 需要数据库中的字段与实体类的属性进行相匹配
        if (StringUtils.isNotBlank(param.getName())){
            queryWrapper.eq(WorkingPersonnel::getName,param.getName());
        }
        // 查询存在的员工
        queryWrapper.eq(WorkingPersonnel::getIsWork,0);
        List<WorkingPersonnel> list = workingPersonnelMapper.selectList(queryWrapper);
        // 处理关联信息
        list.forEach(dList ->{
            // 保存公司对象信息
            dList.setCompany(hupCompanyMapper.selectById(dList.getCompanyId()));
        });
        return new PageInfo<>(list);
    }
}
